#!/usr/bin/python

# Python script for Nepomuk firefox
print "Script relatedRes.py in the position"

#get the argument from parent window
arg0 = window.arguments[0];
arg1 = window.arguments[1];

# attach TheNepomukWhisperer to the document
from the_nepomuk_whisperer import TheNepomukWhisperer
document.NEPO = TheNepomukWhisperer(ONTOLOGIES_STORAGE_FILE)

# retrive the related resources
theResources = document.NEPO.pimo.getRelatedResources(arg0, arg1)

mylist = document.getElementById("ResourceList")
while mylist.childNodes.length != 1:
	mylist.removeChild(mylist.lastChild)

for theResource in theResources:
	print theResource
	row = document.createElement('listitem')
	row.setAttribute('value', theResource)
	row.setAttribute('tooltiptext', theResource)
	
	if len(theResource) >40:
		theResource = theResource[0:38]+"..."
	
	cell = document.createElement('listcell')
	cell.setAttribute('label', theResource)
	row.appendChild(cell)
	
	mylist.appendChild(row);